/**
 * <pre>
 * Copyright 2008 Antonio Jacob Costa (jacob.costa@gmail.com)
 * 
 * Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at 
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an &quot;AS IS&quot; BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and 
 * limitations under the License.
 * </pre>
 */
package org.ajc.maximo4eclipse.templates;

import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Path;

/**
 * <p>
 * Manages the creation of each of the files/classes necessary to extend an Mbo.
 * </p>
 * 
 * @author Antonio Jacob Costa
 */
public class MboTemplate extends DefaultTemplate {
  /**
   * 
   */
  public MboTemplate() {
  }
  
  @Override
  public void createFile(String mboName, String packageName,
      String superclassName, IProgressMonitor monitor, IResource resource)
      throws CoreException {
    IContainer container = (IContainer) resource;
    String folderName = packageName.replace(".", "/");
    final IFile file = container.getFile(new Path(folderName.concat("/")
        .concat(mboName).concat(".java")));
    final IFile fileSet = container.getFile(new Path(folderName.concat("/")
        .concat(mboName).concat("Set.java")));
    final IFile fileRemote = container.getFile(new Path(folderName.concat("/")
        .concat(mboName).concat("Remote.java")));
    final IFile fileSetRemote = container.getFile(new Path(folderName.concat(
        "/").concat(mboName).concat("SetRemote.java")));
    createFile(folderName, file, monitor, container, Mbo.openContentStream(
        mboName, packageName, superclassName));
    createFile(folderName, fileSet, monitor, container, MboSet
        .openContentStream(mboName, packageName, superclassName));
    createFile(folderName, fileRemote, monitor, container, MboRemote
        .openContentStream(mboName, packageName, superclassName));
    createFile(folderName, fileSetRemote, monitor, container, MboSetRemote
        .openContentStream(mboName, packageName, superclassName));
  }
}
